package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    //活动列表分页查询
    @GetMapping("/activities")
    public Result list(Integer channel, Integer type, Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")  Integer pageSize) {
        log.info("活动列表查询    " + channel + "  " + type + "  " + status + "  " + page + "  " + pageSize);
        PageResult<Activity> pageResult = activityService.list(channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }
    //根据ID删除活动数据
    @DeleteMapping("/activities/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动  " + id);
        activityService.delete(id);
        return Result.success();
    }
    //添加活动
    @PostMapping("/activities")
    public Result add(@RequestBody Activity activity) {
        log.info("添加活动  " + activity);
        activityService.add(activity);
        return Result.success();
    }
    //根据ID查询活动数据
    @GetMapping("/activities/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("查询活动  " + id);
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }
    //修改活动数据
    @PutMapping("/activities")
    public Result update(@RequestBody Activity activity) {
        log.info("修改活动  " + activity);
        activityService.update(activity);
        return Result.success();
    }
    //查询指定类型的所有活动数据
//    请求路径：/activities/type/{type}
//    请求方式：GET
    @GetMapping("/activities/type/{type}")
    public Result listByType(@PathVariable Integer type) {
        log.info("查询指定类型活动  " + type);
        List<Activity> list = activityService.listByType(type);
        return Result.success(list);
    }

//    /activities/list
    //查询所有活动数据
    @GetMapping("/activities/list")
    public Result list() {
        log.info("查询所有活动");
        List<Activity> list = activityService.list();
        return Result.success(list);

    }
}
